//
//  CaoZuoViewController.m
//  LiXingZuLin
//
//  Created by ypj on 2021/10/8.
//

#import "LXHomeViewController.h"
#import "JingYingTableViewCell.h"
#import "GongZuoTaiHeaderView.h"
#import "HomeCategoryView.h"
#import "PersonCenterViewController.h"
#import "ZhiWeiGuanLiVC.h"
#import "LXCarIdleListViewController.h"
#import "AppDelegate+Net.h"
#import "CaoZuoTaiModel.h"
#import "QuanXianModel.h"
#import "LXCustomerApplyViewController.h"
#import "CheLiangViewController.h"
#import "LXYearCheckApplyViewController.h"       //新增年检
#import "LXInsuranceApplyViewController.h"
#import "LXRepairApplyViewController.h"
#import "LXMainTainApplyViewController.h"
#import "LXYearCheckRecordViewController.h"
#import "LXCarAddViewController.h"
#import "LXSignContractApplyViewController.h"
#import "LXCarSellBaseViewController.h"
#import "LXInsuranceRecordViewController.h"
#import "LXRepairRecordViewController.h"
#import "LXAllCarListViewController.h"
#import "LXCarOerderRecordViewController.h"
#import "LXPaymentApplyViewController.h"
#import "LXCarLeaseApplyViewController.h"
#import "LXAppointmemtViewController.h"
#import "LXNoticeScrollView.h"

#import "LXHomeItemTableViewCell.h"
#import "LXNoticeTableViewCell.h"
#import "LXHomeManagementCell.h"
#import "LXCarStockViewController.h"
#import "LXAddSignViewController.h"
#import "LXCarSellApplyViewController.h"
#import "LXScheduleViewController.h"
#import "LXWaitProcessingViewController.h"
#import "LXSignRecordViewController.h"
#import "LXUrgingRentListViewController.h"
#import "LXViolationApplyViewController.h"
#import "LXCooperationListViewController.h"
@interface LXHomeViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic) NSMutableArray *data;

@property (nonatomic)  UITableView *tableView;

@property (nonatomic) NSArray *qxArray;// 权限工作台
@property (nonatomic) CaoZuoTaiModel *jyModel;// 经营状况
@property (nonatomic) CaoZuoTaiModel *rmModel;// 代办提醒
@property (nonatomic) NSArray *rcArray;// 日程提醒
@property (nonatomic) NSInteger requestNum;// 4 请求完成

@property (nonatomic) NSArray *children;

@end

@implementation LXHomeViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar setHidden:YES];
    
    [self loadData];
    

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.data = [NSMutableArray array];

    [self createTableView];
    
    
}

-(void)createTableView{
    
    UIImage *img = Image(@"navBack");
    UIImageView *backImageV = [[UIImageView alloc] initWithImage:img];
    backImageV.frame = CGRectMake(0, 0, kScreenWidth, img.size.height);
    backImageV.userInteractionEnabled = YES;
    [self.view addSubview:backImageV];

    
    UILabel *userNameL = [[UILabel alloc] initWithFrame:CGRectMake(20, backImageV.centerY - 10, kScreenWidth - 30, 22)];
    [backImageV addSubview:userNameL];
    YLUserInfo *user = [YLUserMgr fetchUser];
    userNameL.text = user.realName;
    userNameL.font = [UIFont systemFontOfSize:FontSize(20) weight:UIFontWeightSemibold];
    userNameL.textColor = UIColor.whiteColor;
    [userNameL sizeToFit];


    UIButton *roleBtn = [[UIButton alloc] initWithFrame:CGRectMake(userNameL.X, userNameL.Y_height + 10, 20, 20)];
    [backImageV addSubview:roleBtn];
    roleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    roleBtn.titleLabel.font = Fond12;
    [roleBtn setTitle:[NSString stringWithFormat:@"%@",[[MSStorageUtils shareInstance] userDefaultGet:COMPANY_ROLE_NAME]] forState:UIControlStateNormal];
    [roleBtn sizeToFit];
    roleBtn.height = 20;

    
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(roleBtn.X_width + 5, roleBtn.Y + 5, 1, 8)];
    line.backgroundColor = [UIColor colorWithHexString:@"#7094FF"];
    [backImageV addSubview:line];

    UIButton *addressBtn = [[UIButton alloc] initWithFrame:CGRectMake(line.X_width + 5, roleBtn.Y, kScreenWidth-160, 20)];
    [backImageV addSubview:addressBtn];
    addressBtn.titleLabel.lineBreakMode = 0;
    addressBtn.titleLabel.font = Fond12;
    addressBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [addressBtn setTitle:[NSString stringWithFormat:@" %@",[YLUserMgr getEnterpriseName]] forState:UIControlStateNormal];
    
    
    UIButton *eduitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    eduitButton.frame = CGRectMake(ScreenWidth - 60, userNameL.Y, 50, 50);
    YLUserInfo *info = [YLUserMgr fetchUser];
    [eduitButton setBackgroundImageForState:UIControlStateNormal withURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL, info.avatar]] placeholderImage:Image(@"header_default")];
    [eduitButton addCorner:eduitButton.width/2 AndLine:UIColor.whiteColor];
    
    [backImageV addSubview:eduitButton];
    
    
    UIButton *clickBtn = [[UIButton alloc] initWithFrame:backImageV.bounds];
    [backImageV addSubview:clickBtn];
    [clickBtn whenTapped:^{
        PersonCenterViewController *VC = [[PersonCenterViewController alloc] init];
        [self pushToNextController:VC];
    }];
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, MaxY(backImageV), ScreenWidth, B_HEIGHT - MaxY(backImageV)) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    self.tableView.estimatedRowHeight = 0;
//    self.tableView.estimatedSectionFooterHeight = 0;
//    self.tableView.estimatedSectionHeaderHeight = 0;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor colorWithHexString:@"#F7F8FA"];
    [self.tableView registerClass:[LXNoticeTableViewCell class] forCellReuseIdentifier:NSStringFromClass([LXNoticeTableViewCell class])];
    [self.tableView registerClass:[LXHomeItemTableViewCell class] forCellReuseIdentifier:NSStringFromClass([LXHomeItemTableViewCell class])];
    [self.tableView registerClass:[LXHomeManagementCell class] forCellReuseIdentifier:NSStringFromClass([LXHomeManagementCell class])];

    [self.view addSubview:self.tableView];
    
//    CGRect frame = CGRectMake(0, 0, 0, 0.1);
//    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:frame];
    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = YES;
    }
    if(@available(iOS 11.0, *)){
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
    }
    
 

}




#pragma mark -- 请求数据
-(void)loadData{
        
    self.requestNum = 0;
    
    
    // 代办提醒
    NSString *jsons = [NSString toJSONData:@[@"7"]];
    [MSNetworkManager getRevertUrl:[DOMAIN_URL stringByAppendingString:GET_GetActivityList] params:@{@"types":jsons} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        if (isSuccess) {
            AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
            NSDictionary *dic = [(NSArray *)resonseObj firstObject];
            if([dic[@"type"] intValue] == 7){
                app.appointCarImageUrl = dic[@"img"];
            }
        }
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:NO];
    
    // 代办提醒
    NSString *url = [DOMAIN_URL stringByAppendingString:GET_GetToDayScheduleUrl];
    [MSNetworkManager getRevertUrl:url params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        self.rcArray = [CaoZuoTaiModel mj_objectArrayWithKeyValuesArray:resonseObj];
        self.requestNum++;
        [self setAllData];
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:NO];
    
    
    // 代办提醒
    NSString *url0 = [DOMAIN_URL stringByAppendingString:kReminder_Url];
    [MSNetworkManager getRevertUrl:url0 params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        
        self.rmModel = [CaoZuoTaiModel mj_objectWithKeyValues:resonseObj];
        self.requestNum++;
        [self setAllData];
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:NO];
 
    // 经营状况
    NSString *url1 = [NSString stringWithFormat:@"%@",POST_KZT];
    [MSNetworkManager postRevertUrl:url1 params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        
        self.jyModel = [CaoZuoTaiModel mj_objectWithKeyValues:resonseObj];
        self.requestNum++;
        [self setAllData];
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:NO];
    
    
    // 权限工作台
    NSString *url2 = [NSString stringWithFormat:@"%@",POST_Jurisdiction];
    [MSNetworkManager postRevertUrl:url2 params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        
        self.qxArray = [QuanXianModel mj_objectArrayWithKeyValuesArray:resonseObj];
        self.requestNum++;
        [self setAllData];
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:NO];
    
    
}


-(void)setAllData{

    if (self.requestNum>=4) {
        [self.data removeAllObjects];
        
        // 日程提醒
        
        NSDictionary *dic0 = @{
            @"key":@"schedule",
            @"title":@"日程提醒",
            @"height":@(68),
            @"children":@[]
        };
        [self.data addObject:[QuanXianModel mj_objectWithKeyValues:dic0]];
        
        
        
       NSDictionary *dic1 =
        @{
            @"key":@"remind",
            @"title":@"待办提醒",
            @"selWho":@(1),
            @"selText":@"展开,收起",
            @"height":@(180),
            @"children":@[
                @{
                    @"name":@"待办提醒",
                    @"isNotUrl":@(1),
                    @"menuId":@"9999",
                    @"remindNum":@(self.rmModel.carTypeCount)
                },
                @{
                    @"name":@"逾期提醒",
                    @"isNotUrl":@(1),
                    @"menuId":@"809",
                    @"remindNum":@(self.rmModel.overDueCount)
                },
                @{
                    @"name":@"今日签约",
                    @"isNotUrl":@(1),
                    @"menuId":@"808",
                    @"remindNum":@(self.rmModel.todaySign)
                },
                @{
                    @"name":@"今日收入",
                    @"isNotUrl":@(1),
                    @"menuId":@"807",
                    @"remindNum":@(self.rmModel.todayRecieve)
                },
//                @{
//                    @"name":@"应收提醒",
//                    @"isNotUrl":@(1),
//                    @"menuId":@"806",
//                    @"remindNum":@(self.rmModel.rentCount)
//                },
                @{
                    @"name":@"年检提醒",
                    @"isNotUrl":@(1),
                    @"menuId":@"805",
                    @"remindNum":@(self.rmModel.yearlyCheckCount)
                },
                @{
                    @"name":@"保险提醒",
                    @"isNotUrl":@(1),
                    @"menuId":@"804",
                    @"remindNum":@(self.rmModel.insuranceCount)
                },
                @{
                    @"name":@"维修提醒",
                    @"isNotUrl":@(1),
                    @"menuId":@"803",
                    @"remindNum":@(self.rmModel.repairCount)
                },
                @{
                    @"name":@"违约提醒",
                    @"isNotUrl":@(1),
                    @"menuId":@"802",
                    @"remindNum":@"0"
                },
                
            ]
        };
        [self.data addObject:[QuanXianModel mj_objectWithKeyValues:dic1]];
        
    
        
        NSDictionary *dic2 =  @{
                @"key":@"management",
                @"title":@"经营状况",
                @"selWho":@(1),
                @"selText":@"车辆,客户",
                @"height":@([LXHomeManagementCell getCellHeightWithDataAry:[self resetChildren:1]]),
                @"children":[self resetChildren:1]
        };
        [self.data addObject:[QuanXianModel mj_objectWithKeyValues:dic2]];

        
        
        
        for (QuanXianModel *model in self.qxArray){
            if ([model.name isEqualToString:@"车管权限"]) {
                NSDictionary *dic = @{
                    @"key":@"carWork",
                    @"title":@"车管工作台",
                    @"height":@([LXHomeItemTableViewCell getCellHeightWithDataAry:model.children]),
                    @"children": model.children
                };
                [self.data addObject:[QuanXianModel mj_objectWithKeyValues:dic]];
                break;
            }
        }
        
        for (QuanXianModel *model in self.qxArray){
            if([model.name isEqualToString:@"销售权限"]){
                NSDictionary *dic = @{
                        @"key":@"xiaoShouWork",
                        @"title":@"销售工作台",
                        @"height":@([LXHomeItemTableViewCell getCellHeightWithDataAry:model.children]),
                        @"children": model.children
                };
                [self.data addObject:[QuanXianModel mj_objectWithKeyValues:dic]];
                break;
            }
        }
        
        
        for (QuanXianModel *model in self.qxArray){
            if([model.name isEqualToString:@"财务权限"]){
                NSDictionary *dic = @{
                        @"key":@"caiwuWork",
                        @"title":@"财务工作台",
                        @"height":@([LXHomeItemTableViewCell getCellHeightWithDataAry:model.children]),
                        @"children": model.children
                };
                [self.data addObject:[QuanXianModel mj_objectWithKeyValues:dic]];
                break;
            }
          
        }
        
      
        [self.tableView reloadData];
    }
    
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.data.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    QuanXianModel *model = self.data[indexPath.section];
    // 日程提醒
    if ([model.key isEqualToString:@"schedule"]) {
        LXNoticeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXNoticeTableViewCell class])];
        cell.notiView.titleArr = self.rcArray;
//        CaoZuoTaiModel *m = [[CaoZuoTaiModel alloc] init];
//        m.address = @"11111234567";
//        m.typeDesc = @"sdfsdf3456789";
//        m.appointmentTime = @"222222345678987654";
//        CaoZuoTaiModel *mm = [[CaoZuoTaiModel alloc] init];
//        mm.address = @"fffffffdfghjkl";
//        mm.typeDesc = @"sdf塑料袋积分sdf";
//        mm.appointmentTime = @"gggggsdfghjkjhgfdsdfgh";
//        cell.notiView.titleArr = @[m,mm];
        [cell.notiView.bgScrollView whenTapped:^{
            LXScheduleViewController *vc = [[LXScheduleViewController alloc] init];
            [self pushToNextController:vc];
             return;
        }];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setClipsToBounds:YES];
        return cell;
    }
    // 代办提醒/经营状况
    else if([model.key isEqualToString:@"remind"] ||
            [model.key isEqualToString:@"management"]){
        LXHomeManagementCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXHomeManagementCell class])];
        [cell setClipsToBounds:YES];
        cell.selectionStyle= UITableViewCellSelectionStyleNone;
        cell.model = model;
        [cell setToChangeValue:^(QuanXianModel * _Nonnull model) {
           
            
            if ([model.key isEqualToString:@"management"]) {
                model.children = [self resetChildren:model.selWho];
                model.height = [LXHomeManagementCell getCellHeightWithDataAry:[self resetChildren:model.selWho]];
            }
           
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            
        }];
        
        
        [self didSelectRowAtIndexPath:cell];
        return cell;
    }
    else {
        LXHomeItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXHomeItemTableViewCell class])];
        [cell setClipsToBounds:YES];
        cell.selectionStyle= UITableViewCellSelectionStyleNone;
        cell.dataAry = model.children;
        cell.tipslabel.text = model.title;
        [self didSelectRowAtIndexPath:cell];
        return cell;
    }
    
   
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    QuanXianModel *model = self.data[indexPath.section];
    return model.height;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 12)];
    view.backgroundColor = UIColor.clearColor;
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 12;
}


#pragma mark -- 点击item
-(void)didSelectRowAtIndexPath:(TableViewCell *)cell{
    
    
    [cell setToSendValue:^(QuanXianSmallModel * _Nonnull model) {
        

        
        #pragma mark -- 代办事项点击
        
        
         if([model.menuId isEqualToString:@"9999"]){
            LXWaitProcessingViewController *vc = [[LXWaitProcessingViewController alloc] init];
           [self pushToNextController:vc];
            return;
       }
        // 年检提醒
        else if([model.menuId isEqualToString:@"805"]){
//            LXYearCheckRecordViewController *vc = [[LXYearCheckRecordViewController alloc] init];
//            vc.type = 2;
//            [self pushToNextController:vc];
//             return;
        }
        // 保险提醒
        else if([model.menuId isEqualToString:@"804"]){
//             LXInsuranceRecordViewController *vc = [[LXInsuranceRecordViewController alloc] init];
//            vc.type = 2;
//            [self pushToNextController:vc];
//             return;
        }
        // 维修车辆提醒
        else if([model.menuId isEqualToString:@"803"]){
//            LXRepairRecordViewController *vc = [[LXRepairRecordViewController alloc] init];
//            vc.type = 2;
//            [self pushToNextController:vc];
//             return;
        }
        // 今日签约
        else if([model.menuId isEqualToString:@"808"]){
            LXSignRecordViewController *vc = [[LXSignRecordViewController alloc] init];
            
            [self pushToNextController:vc];
             return;
        }
        
        #pragma mark -- 经营状况点击
        // 全部车型
        else if ([model.menuId isEqualToString:@"910"]){
    
//            LXAllCarListViewController *vc = [[LXAllCarListViewController alloc] init];
//            [self pushToNextController:vc];
//             return;
            
            LXCarStockViewController *vc = [[LXCarStockViewController alloc] init];
            [self pushToNextController:vc];
            return;
            
        }
        // 全部车辆
        else if ([model.menuId isEqualToString:@"909"]){
    
//            LXAllCarListViewController *vc = [[LXAllCarListViewController alloc] init];
//            [self pushToNextController:vc];
            
            
            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UIViewController *controller = appDelegate.window.rootViewController;
            LiXingMainTabbarVC *rvc = (LiXingMainTabbarVC *)controller;
            [rvc setSelectedIndex:3];//需要跳转的tabBar的索引，tabBar默认的索引是从0开始的。
            [self.navigationController popToRootViewControllerAnimated:YES];
            return;
        }
        
        // 已出租车辆
        else if ([model.menuId isEqualToString:@"908"]){
            AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UIViewController *controller = appDelegate.window.rootViewController;
            LiXingMainTabbarVC *rvc = (LiXingMainTabbarVC *)controller;
            [rvc setSelectedIndex:3];//需要跳转的tabBar的索引，tabBar默认的索引是从0开始的。
            [self.navigationController popToRootViewControllerAnimated:YES];
            [kNotifyCenter postNotificationName:@"CarstatusChange" object:@"1"];
            return;
        }
        // 出租中车辆
        else if ([model.menuId isEqualToString:@"907"]){
            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UIViewController *controller = appDelegate.window.rootViewController;
            LiXingMainTabbarVC *rvc = (LiXingMainTabbarVC *)controller;
            [rvc setSelectedIndex:3];//需要跳转的tabBar的索引，tabBar默认的索引是从0开始的。
            [self.navigationController popToRootViewControllerAnimated:YES];
            [kNotifyCenter postNotificationName:@"CarstatusChange" object:@"2"];
            return;
        }
        // 未出租车辆
        else if ([model.menuId isEqualToString:@"906"]){
            
            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UIViewController *controller = appDelegate.window.rootViewController;
            LiXingMainTabbarVC *rvc = (LiXingMainTabbarVC *)controller;
            [rvc setSelectedIndex:3];//需要跳转的tabBar的索引，tabBar默认的索引是从0开始的。
            [self.navigationController popToRootViewControllerAnimated:YES];
            [kNotifyCenter postNotificationName:@"CarstatusChange" object:@"3"];
            return;
        }
        
        // 已出售的车辆
        else if ([model.menuId isEqualToString:@"905"]){
            
            LXCarSellBaseViewController *vc = [[LXCarSellBaseViewController alloc] init];
            vc.selectIndex = 1;
            [self pushToNextController:vc];
            return;
            
        }
        
        // 出售中的车辆
        else if ([model.menuId isEqualToString:@"904"]){
            
            LXCarSellBaseViewController *vc = [[LXCarSellBaseViewController alloc] init];
            vc.selectIndex = 2;
            [self pushToNextController:vc];
            return;
            
        }
        // 未出售的车辆
        else if ([model.menuId isEqualToString:@"903"]){
            
            LXCarSellBaseViewController *vc = [[LXCarSellBaseViewController alloc] init];
            vc.selectIndex = 3;
            [self pushToNextController:vc];
            return;
            
        }
        // 全部客户
        else if ([model.menuId isEqualToString:@"709"]){
            
            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UIViewController *controller = appDelegate.window.rootViewController;
            LiXingMainTabbarVC *rvc = (LiXingMainTabbarVC *)controller;
            [rvc setSelectedIndex:3];//需要跳转的tabBar的索引，tabBar默认的索引是从0开始的。
            [self.navigationController popToRootViewControllerAnimated:YES];
            [kNotifyCenter postNotificationName:@"customerStatusChange" object:@"0"];
        }
        // 已签客户
        else if ([model.menuId isEqualToString:@"708"]){
            
            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UIViewController *controller = appDelegate.window.rootViewController;
            LiXingMainTabbarVC *rvc = (LiXingMainTabbarVC *)controller;
            [rvc setSelectedIndex:3];//需要跳转的tabBar的索引，tabBar默认的索引是从0开始的。
            [self.navigationController popToRootViewControllerAnimated:YES];
            [kNotifyCenter postNotificationName:@"customerStatusChange" object:@"1"];
        }
        // 逾期客户
        else if ([model.menuId isEqualToString:@"707"]){
            
            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UIViewController *controller = appDelegate.window.rootViewController;
            LiXingMainTabbarVC *rvc = (LiXingMainTabbarVC *)controller;
            [rvc setSelectedIndex:3];//需要跳转的tabBar的索引，tabBar默认的索引是从0开始的。
            [self.navigationController popToRootViewControllerAnimated:YES];
            [kNotifyCenter postNotificationName:@"customerStatusChange" object:@"2"];
        }
        
       //新增车辆
      else if ([model.menuId isEqualToString:@"10088"]){

          LXCarAddViewController *vc =[[LXCarAddViewController alloc] init];
          [self pushToNextController:vc];
          
        }
        
      // 发布出租
      else if ([model.menuId isEqualToString:@"10159"]){
            
//          LXCarIdleListViewController *VC = [[LXCarIdleListViewController alloc] init];
//            [self pushToNextController:VC];
          
          LXCarLeaseApplyViewController *vc = [[LXCarLeaseApplyViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
          
      }
    // 出售管理
      else if ([model.menuId isEqualToString:@"10160"]){
    
//          LXCarSellBaseViewController *vc = [[LXCarSellBaseViewController alloc] init];
//          [self pushToNextController:vc];
//          return;
          LXCarSellApplyViewController *vc = [[LXCarSellApplyViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
          return;
      }
        //新增年检
      else if ([model.menuId isEqualToString:@"10151"]){
          LXYearCheckApplyViewController *vc = [[LXYearCheckApplyViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
      }
        //新增维修
      else if ([model.menuId isEqualToString:@"10153"]){
          LXRepairApplyViewController *vc = [[LXRepairApplyViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
      }
        // 新增保险
      else if ([model.menuId isEqualToString:@"10154"]){
          LXInsuranceApplyViewController *vc = [[LXInsuranceApplyViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
      }
        //新增保养 
      else if ([model.menuId isEqualToString:@"10152"]){
          LXMainTainApplyViewController *vc = [[LXMainTainApplyViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
      }
        //新增签约
      else if ([model.menuId isEqualToString:@"10156"]){
          
          LXSignContractApplyViewController *vc = [[LXSignContractApplyViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
          
//          LXAddSignViewController *vc = [[LXAddSignViewController alloc] init];
////          vc.type = 1;
//          [self pushToNextController:vc];
      }
        // 新增违约
      else if([model.menuId isEqualToString:@"10157"]){
          LXViolationApplyViewController *vc = [[LXViolationApplyViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
      }
        // 合作修理厂
      else if([model.menuId isEqualToString:@"10320"]){
          LXCooperationListViewController *vc = [[LXCooperationListViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
      }
        // 合作公司
      else if([model.menuId isEqualToString:@"10321"]){
          LXCooperationListViewController *vc = [[LXCooperationListViewController alloc] init];
          vc.type = 2;
          [self pushToNextController:vc];
      }
        //下定提醒
      else if ([model.menuId isEqualToString:@"10233"]){
          LXCarOerderRecordViewController *vc = [[LXCarOerderRecordViewController alloc] init];
          vc.type = 2;
          [self pushToNextController:vc];
      }
        //下定记录
      else if ([model.menuId isEqualToString:@"10166"]){
          LXCarOerderRecordViewController *vc = [[LXCarOerderRecordViewController alloc] init];
          vc.type = 1;
          [self pushToNextController:vc];
      }
     
        // 职位管理
       else if ([model.menuId isEqualToString:@"10093"]){
            //职位管理
            ZhiWeiGuanLiVC *vc = [[ZhiWeiGuanLiVC alloc] init];
            [self pushToNextController:vc];
        }
        // 预约管理
       else if([model.menuId isEqualToString:@"10202"]){
           LXAppointmemtViewController *vc = [LXAppointmemtViewController new];
           [self pushToNextController:vc];
           return;
       }
        // 车型库存
       else if([model.menuId isEqualToString:@"10203"]){
           LXCarStockViewController *vc = [[LXCarStockViewController alloc] init];
           [self pushToNextController:vc];
           return;
       }
    
        //新增付款
        else if ([model.menuId isEqualToString:@"10095"]){
            LXPaymentApplyViewController *vc = [[LXPaymentApplyViewController alloc] init];
            vc.type = 2;
            [self pushToNextController:vc];
        }
        //新增收款
        else if ([model.menuId isEqualToString:@"10094"]){
            LXPaymentApplyViewController *vc = [[LXPaymentApplyViewController alloc] init];
            vc.type = 1;
            [self pushToNextController:vc];
        }
        //新增客户
       else if([model.menuId isEqualToString:@"10089"]){
           
           LXCustomerApplyViewController *vc = [[LXCustomerApplyViewController alloc] init];
           vc.type = 1;
           [self pushToNextController:vc];
           return;

       }
        // 签约管理
       else if([model.menuId isEqualToString:@"10231"]){
           
           LXSignRecordViewController *vc = [[LXSignRecordViewController alloc] init];
           
           [self pushToNextController:vc];
           
           return;
       }
        // 一键催租
       else if([model.menuId isEqualToString:@"10232"]){
           
           LXUrgingRentListViewController *vc = [[LXUrgingRentListViewController alloc] init];
           [self pushToNextController:vc];
           return;
       }
        else {
            showAlert(@"此功能暂未开放");
        }
        
        
        
    }];
}

/**type 1 默认选择了车辆 2 选择了客户*/
-(NSArray *)resetChildren:(NSInteger)type{
    
    NSArray *ary;
    if (type == 1) {
        ary = @[
            @{
                @"name":@"全部车型",
                @"sectionType":@(1),
                @"menuId":@"910",
                @"remindNum":@(self.jyModel.carTypeCount)
            },
            @{
                @"name":@"全部车辆",
                @"sectionType":@(1),
                @"menuId":@"909",
                @"remindNum":@(self.jyModel.allCar)
            },
            @{
                @"name":@"出租签约",
                @"sectionType":@(1),
                @"menuId":@"",
                @"remindNum":@(self.jyModel.signRentCount)
            },
            @{
                @"name":@"出售签约",
                @"sectionType":@(1),
                @"menuId":@"",
                @"remindNum":@(self.jyModel.signSaleCount)
            },
//            @{
//                @"name":@"已出租",
//                @"sectionType":@(1),
//                @"menuId":@"908",
//                @"remindNum":@(self.jyModel.rentedCar)
//            },
//            @{
//                @"name":@"出租中",
//                @"sectionType":@(1),
//                @"menuId":@"907",
//                @"remindNum":@(self.jyModel.waitRentCar)
//            },
//            @{
//                @"name":@"未出租",
//                @"sectionType":@(1),
//                @"menuId":@"906",
//                @"remindNum":@(self.jyModel.notRentCar)
//            },
//            @{
//                @"name":@"已出售",
//                @"sectionType":@(1),
//                @"menuId":@"905",
//                @"remindNum":@(self.jyModel.saledCar)
//            },
//            @{
//                @"name":@"出售中",
//                @"sectionType":@(1),
//                @"menuId":@"904",
//                @"remindNum":@(self.jyModel.waitSaleCar)
//            },
//            @{
//                @"name":@"未出售",
//                @"sectionType":@(1),
//                @"menuId":@"903",
//                @"remindNum":@(self.jyModel.notSaleCar)
//            },

        ];
    }
    else{
        ary  = @[
            @{
            @"name":@"全部客户",
            @"sectionType":@(2),
            @"menuId":@"709",
            @"remindNum":@(self.jyModel.allCustom)
        },
        @{
            @"name":@"已签客户",
            @"sectionType":@(2),
            @"menuId":@"708",
            @"remindNum":@(self.jyModel.customRentedCar)
        },
        @{
            @"name":@"逾期客户",
            @"sectionType":@(2),
            @"menuId":@"707",
            @"remindNum":@(self.jyModel.customNotRentCar)
        },

        ];
    }
    
    return [QuanXianSmallModel mj_objectArrayWithKeyValuesArray:ary];
   
}
@end
